﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;

namespace S.Breed.Domain
{
    public class MyDbContext : DbContext
    {
        public MyDbContext(DbContextOptions<MyDbContext> options) : base(options)
        {
        }
        public DbSet<MaternalMatingModel> MaternalMatingModel { get; set; }

        // 添加与Dapper集成的方法来执行数据库操作
        public T ExecuteQuery<T>(string sql, object parameters = null)
        {
            using IDbConnection connection = new SqlConnection(Database.GetDbConnection().ConnectionString);
            return connection.QueryFirstOrDefault<T>(sql, parameters, commandType: CommandType.Text);
        }

        public int ExecuteCommand(string sql, object parameters = null)
        {
            using IDbConnection connection = new SqlConnection(Database.GetDbConnection().ConnectionString);
            return connection.Execute(sql, parameters, commandType: CommandType.Text);
        }
    }
}
